import Vue from 'vue'
import Vuex from 'vuex' //引入vuex
Vue.use(Vuex) //使用vuex

const actions = { //用于响应组件中动作(服务员,业务逻辑)
    jia(context, value) {
        //context.commit('JIA', value)
        context.dispatch('jia2', value)
    },
    jia2(context, value) {
        console.log('jia2')
        context.commit('JIA', value)
    },
    jian(context, value) {
        context.commit('JIAN', value)
    }
}
const mutations = { //用于操作数据(后厨,具体操作)
    JIA(state, value) {
        state.sum += value
    },
    JIAN(state, value) {
        state.sum -= value
    }
}
const state = { //用于存储数据
    sum: 10,
    school: '清华'
}
const getters = { //用于加工state中数据
    bigSum(state) {
        return state.sum * 10
    }
}

export default new Vuex.Store({ //创建store
    actions,
    mutations,
    state,
    getters
})